package com.zlyx.easy.swagger;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import com.fasterxml.classmate.TypeResolver;
import com.zlyx.easy.swagger.config.EasySwaggerConfiguration;
import com.zlyx.easy.swagger.plugins.EasySwaggerApiModelPropertyPropertyBuilder;
import com.zlyx.easy.swagger.plugins.EasySwaggerApiParamParameterBuilder;
import com.zlyx.easy.swagger.plugins.EasySwaggerOperationModelsProvider;
import com.zlyx.easy.swagger.plugins.EasySwaggerOperationNotesReader;
import com.zlyx.easy.swagger.plugins.EasySwaggerOperationSummaryReader;
import com.zlyx.easy.swagger.plugins.EasySwaggerOperationTagsReader;
import com.zlyx.easy.swagger.plugins.EasySwaggerRequestParamParameterBuilder;
import com.zlyx.easy.swagger.plugins.EasySwaggerResponseMessageReader;
import com.zlyx.easy.swagger.plugins.EasySwaggerSpringMappingParametersReader;

import springfox.documentation.schema.TypeNameExtractor;
import springfox.documentation.spi.schema.EnumTypeDeterminer;
import springfox.documentation.spi.schema.ModelPropertyBuilderPlugin;
import springfox.documentation.spi.service.OperationBuilderPlugin;
import springfox.documentation.spi.service.OperationModelsProviderPlugin;
import springfox.documentation.spi.service.ParameterBuilderPlugin;
import springfox.documentation.spring.web.DescriptionResolver;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
@EnableAspectJAutoProxy
public class SwaggerManager {

	@Bean("defaultApiConfiguration")
	@ConditionalOnMissingBean
	public EasySwaggerConfiguration apiConfiguration() {
		return new EasySwaggerConfiguration();
	}

	@Bean
	public OperationBuilderPlugin createOperationImplicitParametersReader(DescriptionResolver descriptions) {
		return new EasySwaggerSpringMappingParametersReader(descriptions);
	}

	@Bean
	public OperationModelsProviderPlugin createOperationModelsProvider(TypeResolver typeResolver) {
		return new EasySwaggerOperationModelsProvider(typeResolver);
	}

	@Bean
	public OperationBuilderPlugin createOperationNotesReader(DescriptionResolver descriptions) {
		return new EasySwaggerOperationNotesReader(descriptions);
	}

	@Bean
	public OperationBuilderPlugin createOperationSummaryReader(DescriptionResolver descriptions) {
		return new EasySwaggerOperationSummaryReader(descriptions);
	}

	@Bean
	public OperationBuilderPlugin createOperationTagsReader() {
		return new EasySwaggerOperationTagsReader();
	}

	@Bean
	public OperationBuilderPlugin createResponseMessageReader(TypeNameExtractor typeNameExtractor,
			TypeResolver typeResolver) {
		return new EasySwaggerResponseMessageReader(typeNameExtractor, typeResolver);
	}

	@Bean
	public ModelPropertyBuilderPlugin createApiModelPropertyPropertyBuilder() {
		return new EasySwaggerApiModelPropertyPropertyBuilder();
	}

	@Bean
	public ParameterBuilderPlugin createApiParamParameterBuilder(DescriptionResolver descriptions,
			EnumTypeDeterminer enumTypeDeterminer) {
		return new EasySwaggerApiParamParameterBuilder(descriptions, enumTypeDeterminer);
	}

	@Bean
	public ParameterBuilderPlugin createRequestParamParameterBuilder() {
		return new EasySwaggerRequestParamParameterBuilder();
	}

}
